//
//  Gastronome.swift
//  SearchBarView
//
//  Created by liaokylin on 2024/10/13.
//

import SwiftUI


struct GastronomeInfo:View {
    var body: some View {
        VStack(alignment:.leading){
            HStack{
                Text("厨房笔记-fang").font(.title2).bold()
                Spacer()
                Image("5").resizable()
                    .frame(width: 80,height: 80)
                    .clipShape(/*@START_MENU_TOKEN@*/Circle()/*@END_MENU_TOKEN@*/)
            }
            Text("女 2023加入 IP属地：广东")
            Text("爱喝汤的小米，分享日常糖糖水水")
            Text("家有猪仔一枚")
        }
        .font(.caption)
        .padding()
    }
}

struct Info:View {
    var body: some View {
        HStack{
            VStack{
                Text("10").bold()
                Text("关注").font(.caption2).foregroundColor(.black.opacity(0.8))
            }
            VStack{
                Text("101").bold()
                Text("粉丝").font(.caption2).foregroundColor(.black.opacity(0.8))
            }
            VStack{
                Text("120").bold()
                Text("关注").font(.caption2).foregroundColor(.black.opacity(0.8))
            }
            VStack{
                Text("108").bold()
                Text("被收藏").font(.caption2).foregroundColor(.black.opacity(0.8))
            }
            VStack{
                Text("120").bold()
                Text("被跟做").font(.caption2).foregroundColor(.black.opacity(0.8))
            }
            Spacer()
            Button(action: {}, label: {
                Text("关注")
                    .foregroundColor(.white)
                    .bold()
            })
            .frame(width: 65,height: 35)
            .background(Color.pink)
            .cornerRadius(16)
        }.padding()
    }
}

struct Gastronome: View {
    @State private var currentSelect: Int = 1
    var tabs :[TabItemValue] = [
        TabItemValue(id: 1, text: "菜谱"),
        TabItemValue(id: 2, text: "作品"),
        TabItemValue(id: 3, text: "收藏"),
    ]
    @Environment(\.presentationMode) var presentationMode

    var body: some View {
        NavigationStack{
            GeometryReader { proxy in
                ScrollView{
                    GastronomeInfo()
                    Info()
                    LazyVStack(spacing: 0, pinnedViews:.sectionHeaders) {
                        Section(header:Tabs(currentSelect: $currentSelect, tabsItems:tabs)){
                            TabView(selection: $currentSelect){
                                ForEach(tabs) { tab in
                                    VStack{
                                        switch currentSelect {
                                        case 1:
                                            Cookbook()
                                        case 2:
                                            works()
                                        case 3:
                                            Collect()
                                        default:
                                            Text("q")
                                        }
                                    }.tag(tab.id)
                                }
                            }
                            .tabViewStyle(.page(indexDisplayMode: .never))
                            .frame(minHeight:proxy.size.height)
                            .padding([.top],10)
                        }
                    }
                }
                .toolbar{
                    ToolbarItem(placement:.topBarLeading){
                        Image(systemName: "chevron.left")
                            .onTapGesture {
                                presentationMode.wrappedValue.dismiss()
                            }
                    }
                    ToolbarItemGroup{
                        Image(systemName: "magnifyingglass")
                        Image(systemName: "ellipsis")
                    }
                }
            }
        }
        .navigationBarBackButtonHidden(true)
        
    }
}

#Preview {
    Gastronome()
}
